<template>
  <div class="r_flex ChannelInput">
    <el-select v-model="channelValue" filterable :placeholder="this.channelName == 'A'?'请选择甲方渠道':'请选择乙方渠道'" @change="cityChange">
      <el-option :label="data.name" :value="data.id" v-for="(data, index) in channelData" :key="index" />
    </el-select>
  </div>
</template>

<script>
import { channelList } from '@/api/business/system'
import { listDept } from '@/api/system/dept'

export default {
  name: 'ChannelInput',
  props: {
    // 城市 - 单选/多选
    channelName: {
      type: String,
      default: 'A'
    },
    // 城市 - input宽度100%/宽度默认
    width100: {
      type: Boolean,
      default: false
    },
    // 全选
    allchecked: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      channelValue: '',
      channelData: '',
    }
  },
  created() {
    // 拉取城市数据
    this.getList()
  },
  mounted() {

  },
  methods: {
    /** 查询城市数据 */
    getList() {
      if (this.channelName == 'A') {
        listDept().then(response => {
          const newparm = response.data
          newparm.map(value=>{
            value.name = value.deptName
            value.id = value.deptId
          })
          this.channelData = newparm
        })
      } else if (this.channelName == 'B') {
        channelList({ pageNum: 1, pageSize: 999,channelType: 1 }).then(response => {
          this.channelData = response.rows
        })
      } else if (this.channelName == 'C') {
        channelList({ pageNum: 1, pageSize: 999,channelType: 2 }).then(response => {
          this.channelData = response.rows
        })
      }else if (this.channelName == 'D') {
        channelList({ pageNum: 1, pageSize: 999,channelType: null }).then(response => {
          this.channelData = response.rows
        })
      }
    },
    // 选择渠道后
    cityChange(data) {
      const parm = this.channelData.filter(value=>{ if(value.id == data){ return value } })[0]
      this.$emit('selectChannel', parm)
    }
  }
}
</script>

